package com.charging.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.charging.common.annotation.Log;
import com.charging.common.core.controller.BaseController;
import com.charging.common.core.domain.AjaxResult;
import com.charging.common.enums.BusinessType;
import com.charging.system.domain.KxCard;
import com.charging.system.service.IKxCardService;
import com.charging.common.utils.poi.ExcelUtil;
import com.charging.common.core.page.TableDataInfo;

/**
 * 电卡管理Controller
 *
 * @author charging
 * @date 2024-04-19
 */
@RestController
@RequestMapping("/system/card")
public class KxCardController extends BaseController
{
    @Autowired
    private IKxCardService kxCardService;

    /**
     * 查询电卡管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:card:list')")
    @GetMapping("/list")
    public TableDataInfo list(KxCard kxCard)
    {
        startPage();
        List<KxCard> list = kxCardService.selectKxCardList(kxCard);
        return getDataTable(list);
    }

    /**
     * 导出电卡管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:card:export')")
    @Log(title = "电卡管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KxCard kxCard)
    {
        List<KxCard> list = kxCardService.selectKxCardList(kxCard);
        ExcelUtil<KxCard> util = new ExcelUtil<KxCard>(KxCard.class);
        util.exportExcel(response, list, "电卡管理数据");
    }

    /**
     * 获取电卡管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:card:query')")
    @GetMapping(value = "/{cardId}")
    public AjaxResult getInfo(@PathVariable("cardId") Long cardId)
    {
        return success(kxCardService.selectKxCardByCardId(cardId));
    }

    /**
     * 新增电卡管理
     */
    @PreAuthorize("@ss.hasPermi('system:card:add')")
    @Log(title = "电卡管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KxCard kxCard)
    {
        return toAjax(kxCardService.insertKxCard(kxCard));
    }

    /**
     * 修改电卡管理
     */
    @PreAuthorize("@ss.hasPermi('system:card:edit')")
    @Log(title = "电卡管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KxCard kxCard)
    {
        return toAjax(kxCardService.updateKxCard(kxCard));
    }

    /**
     * 删除电卡管理
     */
    @PreAuthorize("@ss.hasPermi('system:card:remove')")
    @Log(title = "电卡管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cardIds}")
    public AjaxResult remove(@PathVariable Long[] cardIds)
    {
        return toAjax(kxCardService.deleteKxCardByCardIds(cardIds));
    }

    /**
     * 电卡赠送金额
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:card:edit')")
    @Log(title = "电卡赠送金额", businessType = BusinessType.UPDATE)
    @PostMapping("/give")
    public AjaxResult giveCard(@RequestBody KxCard kxCard){
        logger.info("电卡id："+ kxCard.getCardId()+",赠送金额："+kxCard.getGive());
        return toAjax(kxCardService.giveCard(kxCard.getCardId(),kxCard.getGive()));
    }
}
